package Controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import Entity.Worker;
import 	Communication.Client;
import Controller.WorkerMainMenuController;
import View.WorkerMainMenuView;

import javax.swing.JButton;

import Controller.PatternController;

public class WorkerMainMenuController {

	private WorkerMainMenuView workerMainMenuView;
	private Client client;
	private int currentWorker;
	
	public WorkerMainMenuController(Client client,
			LoginController loginController) {
		this.client = client;
		workerMainMenuView = new WorkerMainMenuView();
		this.showWindow();
		workerMainMenuView.getLogoutBtn().setLocation(144, 295);
		workerMainMenuView.addWorkerMainMenuListener(new WorkerMainMenuListener(loginController));
	}

	
	
	
	public void showWindow() {
		workerMainMenuView.showWindow();
	}


	
	/**
	 *  Hides worker main menu window
	 */
	public void hideWindow() {
		workerMainMenuView.hideWindow();
	}
	
	class WorkerMainMenuListener implements ActionListener {
		LoginController loginController;
 
		AddNewCustomerController  addNewCustomerController;
		RunSaleController      runSaleController;
		PatternController   patternController;
		UpdateCustomerController  updateCustomerController;
		NewProductToCatalogController newProductToCatalogController;
		HandleCatalogController   handleCatalogController;
		//ReportsController        reportsController;
		

		public WorkerMainMenuListener(LoginController loginController) {
			this.loginController = loginController;

			//addNewCustomerController = new AddNewCustomerController(
					//client, WorkerMainMenuController.this);

			//runSaleController = new RunSaleController(client,
				//	WorkerMainMenuController.this);//
			// customerInfoController = new CustomerInfoController(client,
			// WorkerMainController.this);;
		}

		// Variables representing all button controllers
		// ************************//
		// ************************//
		// ************************//

		@Override
		public void actionPerformed(ActionEvent event) {

			if (event.getSource() == workerMainMenuView.getEnterNewCustomerBtn()) {

					addNewCustomerController = new AddNewCustomerController(
						client, WorkerMainMenuController.this);
					
			}

			else if (event.getSource() == workerMainMenuView.getProductToCatalogBtn()) {
				newProductToCatalogController = new NewProductToCatalogController(
						client, WorkerMainMenuController.this);
			}
			else if (event.getSource() == workerMainMenuView.getUpdateCustomerBtn()) {
				updateCustomerController = new UpdateCustomerController(
						client, WorkerMainMenuController.this);
				}
			else if (event.getSource() == workerMainMenuView. getNewPatternBtn()) {
				patternController= new PatternController(client, WorkerMainMenuController.this);

				}

			else if (event.getSource() == workerMainMenuView.getProductToCatalogBtn()) {
				newProductToCatalogController= new NewProductToCatalogController(client, WorkerMainMenuController.this); 
				}
			else if (event.getSource() == workerMainMenuView.getRunSaleBtn()) {
				 runSaleController= new RunSaleController(client, WorkerMainMenuController.this);
			}
			//else if (event.getSource() == workerMainMenuView.getReportsnBtn()) {
				//reportsController= new ReportsController(client, WorkerMainMenuController.this);
			//}
			
			else if (event.getSource() == workerMainMenuView. getHandleCatalogBtn()) {
				handleCatalogController= new HandleCatalogController(client, WorkerMainMenuController.this);
			}
			else if (event.getSource() == workerMainMenuView. getLogoutBtn()) {
				new LoginController(client);
			}
	}
	}
	
	/**
	 * @param availableButtons setup the available Button
	 */
	public void setActiveButtons(boolean[] availableButtons) {

		if (availableButtons[0] == false)
			workerMainMenuView.getEnterNewCustomerBtn().setEnabled(false);

		if (availableButtons[1] == false)
			workerMainMenuView.getNewPatternBtn().setEnabled(false);

		if (availableButtons[2] == false)
			workerMainMenuView.getProductToCatalogBtn().setEnabled(false);

		if (availableButtons[3] == false)
			workerMainMenuView.getRunSaleBtn().setEnabled(false);

		
		if (availableButtons[4] == false)
			workerMainMenuView.getHandleSaleBtn().setEnabled(false);

		if (availableButtons[5] == false)
			workerMainMenuView.getReportsnBtn().setEnabled(false);

		if (availableButtons[6] == false)
			workerMainMenuView.getHandleCatalogBtn().setEnabled(false);
		
		if (availableButtons[7] == false)			//hila
			workerMainMenuView.getUpdateCustomerBtn().setEnabled(false);
		
		workerMainMenuView.getLogoutBtn().setEnabled(true);
	}

	
	/**
	 * 
	 */
	public void enableAll() {
		workerMainMenuView.getEnterNewCustomerBtn().setEnabled(true);

		workerMainMenuView.getNewPatternBtn().setEnabled(true);

		workerMainMenuView.getProductToCatalogBtn().setEnabled(true);

		workerMainMenuView.getRunSaleBtn().setEnabled(true);

		workerMainMenuView.getHandleSaleBtn().setEnabled(true);

		workerMainMenuView.getReportsnBtn().setEnabled(true);

		workerMainMenuView.getHandleCatalogBtn().setEnabled(true);
		
		workerMainMenuView.getUpdateCustomerBtn().setEnabled(true);
		
		workerMainMenuView.getLogoutBtn().setEnabled(true);//hila
	}




}


	

	
